/*
 * FileOutputHandler.java
 * 
 * Created on 2007-nov-01, 08:47:12
 * 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package grex.IO;

import grex.ErrorManagement.ErrorManager;
import grex.ErrorManagement.EvolutionListener;
import grex.EvolutionProcess;
import grex.Options;
import grex.SimplificationListener;
import grex.Simplyfier;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

/**
 *
 * @author RIK
 */
public class FileOutputHandler implements EvolutionListener, SimplificationListener{
    
    private PrintWriter file;
    private Options ops;
    private String fileName="";
    public FileOutputHandler(Options o){
        ops = o;
    }
    public FileOutputHandler(){
    }
    public void closeFile(){
        file.close();
    }
    public void printString(String s){
        file.println(s);
    }
    public void openFile(String fileName) {
        try {                   
            file = new PrintWriter(new FileWriter(fileName));
        } catch (IOException ex) {
            ErrorManager.getInstance().reportError(ex);
        }
    }

    public void evolutionStarted(EvolutionProcess source) {
        
    }
public void batchTerminated(EvolutionProcess source){
        
    }
    public void generationTerminated(EvolutionProcess source) {
        
    }

    public void evolutionTerminated(EvolutionProcess source) {
        file.println("------------Best GP in Batch:-----------------");
        file.println(source.getBestGpFromBatch());
    }

    public void simplificationStarted(Simplyfier source) {
        
    }

    public void simplificationGenerationTerminated(Simplyfier source) {
        
    }

    public void simplifictionTerminated(Simplyfier source) {
        file.println("------------Simplified GP-----------------");
        file.println(source.getSimplyfiedGP());
    }
public void evolutionProcessTerminated(EvolutionProcess source){
        
    }
}
